import javax.swing.tree.TreeNode;

public class Test{

        public int sumNumbers(TreeNode root) {
            // write your code here
            return dfs(root,0);

        }

        public int dfs(TreeNode root,int preSum){
            preSum = preSum*10 + root.val;
            if(root.left == null && root.right == null) return preSum;
            int ret = 0;
            if(root.left != null){
                ret += dfs(root.left,preSum);
            }
            if(root.right != null){
                ret += dfs(root.right,preSum);
            }
            return ret;

        }

}
